﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using IOSpro.Models;
using IOSpro.Lib;
using IosDatamodel;

namespace IOSpro.Controllers
{
    public class CommentsController : Controller
    {
        //
        // GET: /Comments/
          private IosDBEntities db;
        private ICommentsBL ibl;

        public CommentsController() 
        {
            db = new IosDBEntities();
            ibl = new CommentsBL(this.ModelState);
          
        }

        public ActionResult Index()
        {
            var comments = from n in db.Comments select n;
            return View(comments);
        }

         [HttpPost]
        public ActionResult VideoComments( string videoId)
        {
            var comments = ibl.GetcommentsList(Convert.ToInt32(videoId));
            return View(comments);
        }


        //
        // GET: /Comments/Details/5

        public ActionResult AddComment()
        {

            return View();
        }

        //[HttpPost]
        //public ActionResult AddComment(CommentInfo Model)
        //{
        //    ibl.AddComment(Model.Email, Model.Comment, Convert.ToInt32(Model.VideoId));
        //    return View();
        //}

        [HttpPost]
        public ActionResult AddComment(string email, string comment, string videoId)
        {
            ibl.AddComment(email, comment, Convert.ToInt32(videoId));
            return View();
        }


        public ActionResult ReplyIndex()
        {
            var reply = from n in db.UserReplys select n;
            return View(reply);
        }

        public ActionResult AddReply()
        {

            return View();
        }
        [HttpPost]
        public ActionResult AddReply(ReplyModel Model)
        {
            ibl.AddReply(Model.Email, Convert.ToInt32(Model.UserCommentId),Model.Replytext);
            return View();
        }

        //[HttpGet]
        //public ActionResult AddReply(string Email, string UserCommentId,string replytext)
        //{
        //    ibl.AddReply(Email, Convert.ToInt32(UserCommentId), replytext);
        //    return View();
        //}
        //[HttpGet]
        //public ActionResult AddComment(string email, string comment, string videoId)
        //{
        //    ibl.AddComment(email, comment, Convert.ToInt32(videoId));
        //    return View();
        //}





        //public ActionResult Details(int id)
        //{
        //    return View();
        //}

        //
        // GET: /Comments/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Comments/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        
        //
        // GET: /Comments/Edit/5
 
        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /Comments/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Comments/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /Comments/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
